<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>发改局</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- IonIcons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="../../plugins/fontawesome-free/css/all.css">
  <link rel="stylesheet" href="../../dist/css/adminlte.css">
</head>

<body class="hold-transition sidebar-mini">
<div class="wrapper">

  <!-- 主内容容器 -->
  <div class="content-wrapper">
    <!-- 容器头标题 -->
    <div class="content-header">
      <div class="container-fluid">

        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">修改项目要件</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">首页</a></li>
              <li class="breadcrumb-item active">修改项目要件</li>
            </ol>
          </div>
        </div>

      </div>

    </div>

    <!-- 主题内容正文 -->
    <div class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">

            <div class="card card-primary">
              <!-- 卡片头部 -->
              <div class="card-header">
                <h3 class="card-title">修改项目要件</h3>
              </div>

              <!-- 表单开始 -->
              <form>
                <div class="card-body">
                  <div class="row">
                    <div class="col-lg-6">

                      <div class="form-group">
                        <label><span style="color: red">*</span>企业选择</label>
                        <select class="form-control" id="enName">
                        </select>
                      </div>

                      <input type="hidden" id="project_id" name="id" th:value="${data.id}" />
                      <div class="form-group">
                        <label><span style="color: red">*</span>项目名称</label>
                        <select class="form-control" id="projectName" name="projectBaseInfoId">
                        </select>
                      </div>

<!--                      <div class="form-group">-->
<!--                        <label for="exampleInputEmail1">产品名称</label>-->
<!--                        <input type="text" class="form-control" id="exampleInputEmail2" name="" value="精镁砂" placeholder="产品名称">-->
<!--                      </div>-->

                      <div class="form-group">
                        <label for="approvalTimeNumber"><span style="color: red">*</span>审批核准备案时间及文号</label>
                        <input type="text" class="form-control" id="approvalTimeNumber" name="approvalTimeNumber" th:value="${data.approvalTimeNumber}" placeholder="审批核准备案时间">
                      </div>

                      <div class="form-group">
                        <label for="policyStandardsInfo"><span style="color: red">*</span>产品政策及行业标准符合情况</label>
                        <input type="text" class="form-control" id="policyStandardsInfo" name="policyStandardsInfo" th:value="${data.policyStandardsInfo}" placeholder="产品政策及行业标准符合情况">
                      </div>

                      <div class="form-group">
                        <label for="energySavingApprovalTimeNumber"><span style="color: red">*</span>节能审查批复时间及文号</label>
                        <input type="text" class="form-control" id="energySavingApprovalTimeNumber" name="energySavingApprovalTimeNumber" th:value="${data.energySavingApprovalTimeNumber}"
                               placeholder="节能审查批复时间及文号">
                      </div>

                      <div class="form-group">
                        <label for="environmentalApprovalTimeNumber"><span style="color: red">*</span>环评审批时间及文号</label>
                        <input type="text" class="form-control" id="environmentalApprovalTimeNumber" name="environmentalApprovalTimeNumber" th:value="${data.environmentalApprovalTimeNumber}"
                               placeholder="环评审批时间及文号">
                      </div>

                    </div>
                    <div class="col-lg-6">

                      <div class="form-group">
                        <label for="environmentalReview"><span style="color: red">*</span>环评复核情况</label>
                        <textarea  class="form-control" id="environmentalReview" name="environmentalReview" th:text="${data.environmentalReview}"
                                   placeholder="环评复核情况"></textarea>
                      </div>

                      <div class="form-group">
                        <label for="approvalOfConstructionPermit"><span style="color: red">*</span>施工许可审批时间及文号</label>
                        <input type="text" class="form-control" id="approvalOfConstructionPermit" name="approvalOfConstructionPermit" th:value="${data.approvalOfConstructionPermit}"
                               placeholder="施工许可审批时间及文号">
                      </div>

                      <div class="form-group">
                        <label for="capacityAcquisitionSituation"><span style="color: red">*</span>产能取得情况</label>
                        <textarea rows="10" class="form-control" id="capacityAcquisitionSituation" name="capacityAcquisitionSituation" th:text="${data.capacityAcquisitionSituation}" placeholder="产能取得情况"></textarea>
                      </div>

                      <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="businessLicenseInfo" name="businessLicenseInfo" th:checked="${data.businessLicenseInfo == '有'? true:false}">
                        <label class="form-check-label" for="businessLicenseInfo">营业执照情况(有/无)</label>
                      </div>

                      <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="isFeasibilityResearchReport" name="isFeasibilityResearchReport" th:checked="${data.isFeasibilityResearchReport == '有'? true:false}">
                        <label class="form-check-label" for="isFeasibilityResearchReport">是否有《可行性研究报告》(有/无)</label>
                      </div>

                      <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="isFeasibilityReviewComments" name="isFeasibilityReviewComments" th:checked="${data.isFeasibilityReviewComments == '有'? true:false}">
                        <label class="form-check-label" for="isFeasibilityReviewComments">是否有《可行性评审意见》(有/无)</label>
                      </div>

                      <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="isEnergyConservationReport" name="isEnergyConservationReport" th:checked="${data.isEnergyConservationReport == '有'? true:false}">
                        <label class="form-check-label" for="isEnergyConservationReport">是否有《节能报告》(有/无)</label>
                      </div>

                      <div class="form-group" th:if="${#httpSession.getAttribute('role_id') == 1}">
                        <label><span style="color: red">*</span>为企业选择关联的用户</label>
                        <select class="form-control" id="userId" name="enUserId">
                        </select>
                      </div>

                      <input type="hidden" id="delete_id" name="deleted" th:value="${data.deleted}" />

                    </div>
                  </div>
                </div>

                <!-- 添加按钮 -->
                <div class="card-footer">
                  <button type="button" class="btn btn-primary" id="save_btn">保存</button>
                </div>

              </form>

            </div>

          </div>

        </div>

      </div>

    </div>

  </div>


  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
  </aside>

  <!-- 版权信息 -->
  <footer class="main-footer">
    <strong>Copyright &copy; 2021 <a href="http://www.chengzhouyun.com/" target="_blank">ChengZhouYun</a>.</strong> All
    rights reserved.
    <div class="float-right d-none d-sm-inline-block">
      <b>Version</b> 1.0
    </div>
  </footer>

</div>


<script src="../../plugins/jquery/jquery.js"></script>
<!-- Bootstrap -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.js"></script>
<!-- AdminLTE -->
<script src="../../dist/js/adminlte.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>


</body>
<script th:inline="javascript">

  // true:数值型的，false：非数值型
  function myIsNaN(value) {
    return !isNaN(value);
  }

  function isPhoneNumber(val){
    var regPos =/^0?1[3|4|5|6|7|8][0-9]\d{8}$/;
    if(regPos.test(val)){
      return true;
    }else {
      return false;
    }
  }

  function isEmptyNull(value){
    if (value == undefined || value == null || value =="") {
      return false;
    }
    return true;
  }

  $(function(){

    const role_id = /*[[${#httpSession.getAttribute('role_id')}]]*/{};  //{}是默认值,/*[[${user}]]*/ 是传进去的值
    const user_id = /*[[${#httpSession.getAttribute('user_id')}]]*/{};  //{}是默认值,/*[[${user}]]*/ 是传进去的值

    // 保存请求
    $("#save_btn").on("click",function(res){

      if(!isEmptyNull($("#enName").val())) {
        alert("请选择企业")
        return;
      }
      if(!isEmptyNull($("#projectName").val())) {
        alert("请选择项目")
        return;
      }
      if(!isEmptyNull($("#approvalTimeNumber").val())) {
        alert("请填写审批核准备案时间")
        return;
      }
      if(!isEmptyNull($("#policyStandardsInfo").val())) {
        alert("请填写产品政策及行业标准符合情况")
        return;
      }
      if(!isEmptyNull($("#energySavingApprovalTimeNumber").val())) {
        alert("请填写节能审查批复时间及文号")
        return;
      }
      if(!isEmptyNull($("#environmentalApprovalTimeNumber").val())) {
        alert("请填写环评审批时间及文号")
        return;
      }
      if(!isEmptyNull($("#environmentalReview").val())) {
        alert("请填写环评复核情况")
        return;
      }
      if(!isEmptyNull($("#approvalOfConstructionPermit").val())) {
        alert("请填写施工许可审批时间及文")
        return;
      }
      if(!isEmptyNull($("#capacityAcquisitionSituation").val())) {
        alert("请填写产能取得情况")
        return;
      }

      if(role_id == 1){
        if(!isEmptyNull($("#userId").val())|| !myIsNaN($("#userId").val())) {
          alert("请选择项目要件关联的用户")
          return;
        }
      }

      var formData = new FormData();
      formData.id = $("#project_id").val();
      formData.projectBaseInfoId = $("#projectName").val();
      formData.approvalTimeNumber = $("#approvalTimeNumber").val();
      formData.policyStandardsInfo = $("#policyStandardsInfo").val();
      formData.energySavingApprovalTimeNumber = $("#energySavingApprovalTimeNumber").val();
      formData.environmentalApprovalTimeNumber = $("#environmentalApprovalTimeNumber").val();
      formData.environmentalReview = $("#environmentalReview").val();
      formData.approvalOfConstructionPermit = $("#approvalOfConstructionPermit").val();
      formData.capacityAcquisitionSituation = $("#capacityAcquisitionSituation").val();
      formData.businessLicenseInfo = $("#businessLicenseInfo").is(":checked");
      formData.isFeasibilityResearchReport = $("#isFeasibilityResearchReport").is(":checked");
      formData.isFeasibilityReviewComments = $("#isFeasibilityReviewComments").is(":checked");
      formData.isEnergyConservationReport = $("#isEnergyConservationReport").is(":checked");
      if (role_id == 1){
        formData.enUserId = $("#userId").val();
      }else {
        formData.enUserId = user_id;
      }

      formData.deleted = $("#delete_id").val();

      $.ajax({
        url:"/reqment/requirements",
        type:"put",
        data: JSON.stringify(formData),
        contentType:"application/json",
        async: false,
        dataType:"json",
        success: function(res){

          if(res.statusCode == 200) {
            alert(res.message);
            // 跳转页面
            location.href = "/page/ProjectDocmentInfo"
          } else{
            alert(res.errorMsg);
          }

        }

      })
    });



    // 登录的角色是管理员的情况下在做请求

    if (role_id == 1) {
      // 请求企业用户列表 2为企业用户列表
      $.get("/usr/user/list/" + 2, function (data) {
        // 取用户下拉框
        var select = document.getElementById("userId");
        // 情况下拉框中的option
        var arr_option = select.options;
        // 先清除在添加
        for (var i = arr_option.length - 1; i >= 0; i--) {
          arr_option.remove(i);
        }
        // 数据状态码为200通过
        if (data.statusCode == 200) {
          // 取到list数据集合
          var list = data.list;
          console.log(list)
          // forEach遍历
          list.forEach(function (item) {
            // 创建select中的option
            var option = document.createElement('option');
            // 赋值用户id给value
            option.value = item.id;
            // 赋值用户名给内容
            option.innerHTML = item.username;
            // 添加到select中
            select.append(option);
          })

          if(role_id == 1) {
            const enUserId = /*[[${data.enUserId}]]*/{};  //{}是默认值,/*[[${user}]]*/ 是传进去的值
            console.log(enUserId)
            $("#userId").val(enUserId);
          }

        }
      })
    }




    // 取下拉框
    var select = document.getElementById("enName");

    // 情况下拉框中的option
    var arr_option = select.options;
    for(var i = arr_option.length-1;i>=0;i--){
      arr_option.remove(i);
    }
    // 判断角色是否为管理员
    if (role_id == 1) {
      // 发起jsonget 请求
      $.getJSON(
              "/en/enterprise/all",
              function(data){
                // 数据状态码为200通过
                if (data.statusCode == 200) {

                  // 取到list数据集合
                  var list = data.list;
                  var option1 = document.createElement('option');
                  option1.innerHTML = "请下拉选择你的企业";
                  select.append(option1);
                  // forEach遍历
                  list.forEach(function(item){
                    // 创建select中的option
                    var option = document.createElement('option');
                    // 赋值id和企业名称
                    option.value = item.id;
                    option.innerHTML = item.enName;
                    // 添加到select中
                    select.append(option);
                  })

                  const enId = /*[[${data.en_id}]]*/{};
                  $("#enName").val(enId);



                  // 取下拉框
                  var projectselect = document.getElementById("projectName");
                  // 清空下拉框中的option
                  var arr_option = projectselect.options;
                  for(var i = arr_option.length-1;i>=0;i--){
                    arr_option.remove(i);
                  }

                  var url = "/project/projectbase/enid/"+ enId
                  // 发起jsonget 请求
                  $.getJSON(
                    url,
                    function(data){

                      // 数据状态码为200通过
                      if (data.statusCode == 200) {

                        // 取到list数据集合
                        var list = data.list;

                        // forEach遍历
                        list.forEach(function(item){
                          // 创建select中的option
                          var option = document.createElement('option');
                          // 赋值id和企业名称
                          option.value = item.id;
                          option.innerHTML = item.projectName;
                          // 添加到select中
                          projectselect.append(option);
                        })

                        const project_name = /*[[${data.project_name}]]*/{};
                        $("#projectName").find("option:contains('"+project_name+"')").attr("selected",true);
                      }
                    }
                  )

                }

              })
    } else {
      $.get("/en/enterprise/userid/"+ user_id,function(data){

        // 数据状态码为200通过
        if (data.statusCode == 200) {
          // 取到list数据集合
          var list = data.list;
          var option_1 = document.createElement('option');
          // 赋值id和企业名称
          option_1.innerHTML = "下拉选择你的企业";
          // 添加到select中
          select.append(option_1);
          // forEach遍历
          list.forEach(function(item){
            // 创建select中的option
            var option = document.createElement('option');
            // 赋值id和企业名称
            option.value = item.id;
            option.innerHTML = item.enName;
            // 添加到select中
            select.append(option)
          })

          const enId = /*[[${data.en_id}]]*/{};
          $("#enName").val(enId);

          // 取下拉框
          var projectselect = document.getElementById("projectName");
          // 清空下拉框中的option
          var arr_option = projectselect.options;
          for(var i = arr_option.length-1;i>=0;i--){
            arr_option.remove(i);
          }

          var url = "/project/projectbase/enid/"+ enId
          // 发起jsonget 请求
          $.getJSON(
                  url,
                  function(data){

                    // 数据状态码为200通过
                    if (data.statusCode == 200) {

                      // 取到list数据集合
                      var list = data.list;

                      // forEach遍历
                      list.forEach(function(item){
                        // 创建select中的option
                        var option = document.createElement('option');
                        // 赋值id和企业名称
                        option.value = item.id;
                        option.innerHTML = item.projectName;
                        // 添加到select中
                        projectselect.append(option);
                      })

                      const project_name = /*[[${data.project_name}]]*/{};

                      $("#projectName").find("option:contains('"+project_name+"')").attr("selected",true);
                    }
                  }
          )
        }
      })
    }





    // 企业下拉注册更变事件
    $("#enName").change(function(data) {
      var enId = $("#enName").val();

      // 取下拉框
      var projectselect = document.getElementById("projectName");
      // 清空下拉框中的option
      var arr_option = projectselect.options;
      for(var i = arr_option.length-1;i>=0;i--){
        arr_option.remove(i);
      }

      var url = "/project/projectbase/enid/"+ enId
      // 发起jsonget 请求
      $.getJSON(
        url,
        function(data){

          // 数据状态码为200通过
          if (data.statusCode == 200) {

            // 取到list数据集合
            var list = data.list;

            // forEach遍历
            list.forEach(function(item){
              // 创建select中的option
              var option = document.createElement('option');
              // 赋值id和企业名称
              option.value = item.id;
              option.innerHTML = item.projectName;
              // 添加到select中
              projectselect.append(option);
            })
          }
        }
      )
    })
  })


</script>
</html>
